﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Bootstrap5.Abstractions;

using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;

namespace Bootstrap5;

[HtmlRole("status")]
public class Spinner:BootstrapComponentBase
{
    [Parameter] public bool Grow { get; set; }
    [Parameter] public bool Small { get; set; }

    [Parameter][CssClass("text-")] public Color? Color { get; set; }
    

    protected override void BuildRenderTree(RenderTreeBuilder builder)
    {
        builder.OpenElement(0, GetHtmlTagName());
        BuildCommonAttributes(builder);
        builder.AddContent(10, (RenderFragment)(loading =>
        {
            loading.OpenElement(0, "div");
            loading.AddAttribute(1, "class", "visually-hidden");
            loading.AddContent(2, "Loading...");
            loading.CloseElement();
        }));
        builder.CloseElement();
    }

    protected override void CreateCssClass(ICssClassBuilder builder)
    {
        var name="border";
        if (Grow)
        {
            name = "grow";
        }
        builder.Add($"spinner-{name}")
            .Add($"spinner-{name}-sm", Small)
            ;
    }
}
